package com.xbongbong.crm.perform.query.list.button;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xbongbong.paas.toolbox.util.StringUtil;
import com.xbongbong.pro.weblist.pojo.TagPojo;
import com.xbongbong.saas.enums.TagEnum;
import org.elasticsearch.common.inject.Singleton;

/**
 * @author 吴峰
 * @date 2021/12/20 20:35
 */
@Singleton
public class ArchivedTag {

    private String attr;

    public String getAttr() {
        return attr;
    }

    public void setAttr(String attr) {
        this.attr = attr + "Tag";
    }


    public ArchivedTag(String attr) {
        this.attr = attr;
    }

    /**
     * “归”字标签
     * @param archivedTagPojo
     * @param tagData
     * @param enable 各个业务有所区别
     */
    public static void setArchivedData(ArchivedTag archivedTagPojo, JSONObject tagData, boolean enable, TagEnum tagEnum) {
        String archivedTag = archivedTagPojo.getAttr();
        if (StringUtil.isNotEmpty(archivedTagPojo.getAttr()) && enable) {
            JSONArray tagPojoList = tagData.getJSONArray(archivedTag) == null ? new JSONArray() : tagData.getJSONArray(archivedTag);
            tagPojoList = tagPojoList == null ? new JSONArray() : tagPojoList;
            tagPojoList.add(new TagPojo(tagEnum));
            tagData.put(archivedTag, tagPojoList);
        }
    }
}
